<?php

namespace common\models;

use Yii;

/**
 * This is the model class for table "{{%ads}}".
 *
 * @property integer $id
 * @property string $picture
 * @property string $url
 * @property integer $status
 * @property string $desc
 */
class Banner extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%banner}}';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['status'], 'integer'],
            [['picture', 'url', 'desc','title','bgpic'], 'string', 'max' => 255],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'picture' => 'Picture',
            'url' => 'Url',
            'status' => 'Status',
            'desc' => 'Desc',
            'title' => 'Title',
            'bgpic' => 'Bgpic',
        ];
    }

    /**
     * 获取所有的轮播图
     * @param $map
     * @return array|\yii\db\ActiveRecord[]
     */
    static public function getAllBanner($map = [])
    {
        $query = static::find()->where($map)->asArray()->all();

        return $query;
    }

    /**
     * 查询一条广告
     * @param $params
     * @return array|null|\yii\db\ActiveRecord
     */
    public static function getFindOne($params)
    {
        return static::find()->where($params)->one();
    }
}
